package com.topfinance.payment.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.topfinance.frame.dao.HibernateEntityDao;
import com.topfinance.frame.exception.AppException;
import com.topfinance.frame.util.StringUtil;
import com.topfinance.payment.ebo.TC2c1BizMatchEbo;
import com.topfinance.payment.ebo.TC2c1EleMatchEbo;
import com.topfinance.payment.service.ITC2C1EleMatchMgr;

/**
 * 该类自动实现了dao的一般方法，如add, remove, update
 * 在service中出现的大部分情况下是在向后台提交数据前的处理(如校验)及获取后台数据后的处理等
 * @author
 *
 */

public class TC2C1EleMatchMgrImpl extends HibernateEntityDao<TC2c1BizMatchEbo> implements ITC2C1EleMatchMgr {

	private static final Log log = LogFactory.getLog(TC2C1EleMatchMgrImpl.class);

	//根据二代的报文码、业务类型、业务种类获得一二代二代业务要素匹配
	public List<TC2c1EleMatchEbo> getAllEleMatch(String msg, String tpcode, String clscode) throws AppException{
		//如果报文码为空，直接返回
		if(StringUtil.isNullStr(msg))
			return new ArrayList();
		
		String hql = " from TC2c1EleMatchEbo m " ;
		String where = "m.msgCode ='" + msg + "'";
		if(StringUtil.isNotNullStr(tpcode))
			where += " and m.tpCode ='" + tpcode + "'";
		if(StringUtil.isNotNullStr(clscode))
			where += " and m.clasCode ='" + clscode + "'";
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where;
		}
		hql = hql + where;
		return find(hql,paramList.toArray());		
	}

	//根据一代的报文码获得一二代二代业务要素匹配
	public List<TC2c1EleMatchEbo> getAllEleMatch(String msg1) throws AppException{
		//如果一代报文码为空，直接返回
		if(StringUtil.isNullStr(msg1))
			return new ArrayList();
		String hql = " from TC2c1EleMatchEbo m " ;
		String where = " and m.msg1Code ='" + msg1 + "'";
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where.substring(4);
		}
		hql = hql + where;
		return find(hql,paramList.toArray());
	}	
}
